public class demo2 {
    public int sumNumbers(TreeNode root) {
        int sum=0;
        return dfs(root,sum);
    }
    public int dfs(TreeNode root,int temp){
        temp=temp*10+root.val;
        if(root.left==null&&root.right==null)return temp;
        int ret=0;
        if(root.left!=null)ret+=dfs(root.left,temp);
        if(root.right!=null)ret+=dfs(root.right,temp);
        return ret;
    }
}
